package com.magicmovie.service.impl;

import com.magicmovie.entity.IndexMovie;
import com.magicmovie.mapper.IndexMovieMapper;
import com.magicmovie.service.IndexMovieService;
import com.magicmovie.utils.ValidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class IndexMovieServiceImpl implements IndexMovieService {
    @Autowired
    private IndexMovieMapper indexMovieMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return indexMovieMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(@RequestBody IndexMovie record) {
        Map map = new HashMap();
        map.put("movieId", record.getMovieId());
        map.put("indexCategoryId", record.getIndexCategoryId());
        List<IndexMovie> list = selectByParams(map);
        if (ValidUtil.isEmpty(list)) {
            return indexMovieMapper.insert(record);
        }
        return 0;
    }

    @Override
    public IndexMovie selectByPrimaryKey(Integer id) {
        return indexMovieMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Map<String, Object>> selectByParams(@RequestBody Map<String, Object> params) {
        return indexMovieMapper.selectByParams(params);
    }

    @Override
    public int updateByPrimaryKey(@RequestBody IndexMovie record) {
        return 0;
    }
}
